package com.mzw.huaxiarealestatebackend.controller;
import com.mzw.huaxiarealestatebackend.entity.BackPage;
import com.mzw.huaxiarealestatebackend.entity.Client;
import com.mzw.huaxiarealestatebackend.entity.Result;
import com.mzw.huaxiarealestatebackend.entity.StaffKpiRecord;
import com.mzw.huaxiarealestatebackend.service.StaffKpiRecordService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (StaffKpiRecord)表控制层
 *
 * @author makejava
 * @since 2023-12-11 16:21:55
 */
@RestController
@RequestMapping("staffKpiRecord")
public class StaffKpiRecordController {
    /**
     * 服务对象
     */
    @Resource
    private StaffKpiRecordService staffKpiRecordService;

    /**
     * 分页查询
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping
    public Result<BackPage<StaffKpiRecord>> queryAll(@RequestParam("currentPage") int currentPage, @RequestParam("pageSize") int pageSize){
        BackPage<StaffKpiRecord> page = staffKpiRecordService.queryByPage(currentPage, pageSize);
        return Result.success(page);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public Result<StaffKpiRecord> queryById(@PathVariable("id") String id) {
        StaffKpiRecord staffKpiRecord = this.staffKpiRecordService.queryById(id);
        if (staffKpiRecord != null){
            return Result.success(staffKpiRecord);
        }else {
            return Result.error("查找失败");
        }
    }

    /**
     * 新增数据
     *
     * @param staffKpiRecord 实体
     * @return 新增结果
     */
    @PostMapping
    public Result add(@RequestBody StaffKpiRecord staffKpiRecord) {
        boolean insert = this.staffKpiRecordService.insert(staffKpiRecord);
        if (insert){
            return Result.success();
        }else {
            return Result.error("添加失败");
        }
    }

    /**
     * 编辑数据
     *
     * @param staffKpiRecord 实体
     * @return 编辑结果
     */
    @PutMapping
    public Result edit(@RequestBody StaffKpiRecord staffKpiRecord) {
        boolean update = this.staffKpiRecordService.update(staffKpiRecord);
        if (update){
            return Result.success();
        }else {
            return Result.error("修改失败");
        }
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public Result<StaffKpiRecord> deleteById(@RequestParam("id") String id) {
        boolean b = this.staffKpiRecordService.deleteById(id);
        if (b){
            return Result.success();
        }
        return Result.error("删除失败");
    }

}

